﻿namespace BloodlustFury.DataMiner
{
	#region "Using Statements"

	using System;
	using System.Collections.Generic;
	using System.ComponentModel;
	using System.Data;
	using System.Drawing;
	using System.Linq;
	using System.Text;
	using System.Windows.Forms;
	using BloodlustFury.DataMiner.Business;

	#endregion

	public partial class StatisticsForm : Form
	{
		public StatisticsForm()
		{
			InitializeComponent();
		}

		private void StatisticsForm_Load(object sender, EventArgs e)
		{
			DataEngine.OnStatisticsGenerated += this.OnStatisticsGenerated;

			if (!DataEngine.StatisticsGenerated)
			{
				if (DataEngine.PredictionsGenerated
						&& DataEngine.TestModulesLoaded
						&& DataEngine.CaseLibraryLoaded
						&& DataEngine.SolutionsLoaded)
				{
					Cursor = Cursors.WaitCursor;

					DataEngine.GenerateStatistics();

					Cursor = Cursors.Default;
				}
			}

			AverageAbsoluteErrorLabel.Text = Statistics.AverageAbsoluteError.ToString();
			AverageRelativeErrorLabel.Text = Statistics.AverageRelativeError.ToString();
			StandardDeviationLabel.Text = Statistics.StandardDeviation.ToString();
			MeanSquaredErrorLabel.Text = Statistics.MeanSquaredError.ToString();
		}

		private void OnStatisticsGenerated(object sender, EventArgs e)
		{
			AverageAbsoluteErrorLabel.Text = Statistics.AverageAbsoluteError.ToString();
			AverageRelativeErrorLabel.Text = Statistics.AverageRelativeError.ToString();
			StandardDeviationLabel.Text = Statistics.StandardDeviation.ToString();
			MeanSquaredErrorLabel.Text = Statistics.MeanSquaredError.ToString();
		}

		private void StatisticsForm_FormClosing(object sender, FormClosingEventArgs e)
		{
			DataEngine.OnStatisticsGenerated -= this.OnStatisticsGenerated;
		}
	}
}
